$(function(){
    var key = getCookie('key');
    if(!key){
        window.location.href = WapSiteUrl+'/tmpl/member/login.html';
    }
    var username = '';
    if(key){
        $.ajax({
            type:'post',
            url:ApiUrl+"/index.php?act=member_index&op=get_point",
            data:{key:key},
            dataType:'json',
            success:function(result){
                console.log(result);
                if (result['code']==200){
                     $('#point').html(result['datas']['member_points']);
                }
            }
        });
    } else {
        window.location.href = "login.html";
    }

    $("#doTransfer").on('click',function(){
        var account = $("#tel").val();
        var points = parseInt($("#points").val());
        var telReg = /^1[3|4|5|7|8][0-9]{9}$/;
        if (account==''){
             creatLayout("请填写手机号");
             return;
        }
        if (points==''){
            creatLayout("转账积分不能为空");
            return;
        }
        var reg = /^[1-9]\d*$/;
        if(!reg.test(points)){
            creatLayout("转账积分必须大于0");
            return;
        }
        if (!telReg.test(account)){
            creatLayout("手机号格式不正确");
            return;
        }
        var hasPoint = parseInt($('#point').html());
        if(points>hasPoint){
            creatLayout("转账积分不能超过已有积分");
            return;
        }
        $.sDialog({
            skin:"block",
            content:'确认提现吗？',
            okBtn:true,
            cancelBtn:true,
            okFn: function() {
                doTransfer();
            }
        });

        function doTransfer() {
            $.ajax({
                type: "POST",
                url: ApiUrl + "/index.php?act=member_index&op=transfer_point",
                data: {key: key, account: account, points: points},
                dataType: "json",
                success: function (resulte) {
                    if (resulte['code'] == 200) {
                        creatLayout(resulte['msg']);
                        window.location.href = "transfer_points_success.html?id=" + resulte['id'];
                    } else {
                        creatLayout(resulte['msg']);
                    }
                }
            })
        }
    });
});